#include <bits/stdc++.h>
using namespace std;
const int N = 10000 + 10;
struct Edge {
  int a, b, w;
} edges[N];
int n, m, k;
int dis[507], backup[507];
int main() {
  cin >> n >> m >> k;
  memset(dis, 0x3f, sizeof(dis));
  dis[1] = 0;
  for (int i = 0; i < m; ++i) {
    cin >> edges[i].a >> edges[i].b >> edges[i].w;
  }
  for (int i = 0; i < k; ++i) {
    memcpy(backup, dis, sizeof dis);
    for (int j = 0; j < m; ++j) {
      auto [a, b, w] = edges[j];
      dis[b] = min(dis[b], backup[a] + w);
    }
  }
  if (dis[n] >= 0x3f3f3f3f / 2)
    cout << "impossible\n";
  else
    cout << dis[n];
}
